package com.ldu.exam.model;

import java.sql.Timestamp;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UpdateTimestamp;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Builder
@Table(name="t_question")
public class TestQuestionModel 
{
	@Id
	@Column(length=32)
	@GeneratedValue(strategy = GenerationType.IDENTITY,generator = "jpa-uuid")
	@GenericGenerator(name = "jpa-uuid",strategy = "uuid.hex")
	private String id;
	
	/**
	 * 试题标题
	 */
	private String title;
	
	/**
	 * 试题内容
	 */
	private String content;
	
	/**
	 * 试题答案
	 */
	private String answer;
	
	/**
	 * 提交答案
	 */
	private String submitAnswer;
	/**
	 * 试题分数
	 */
	private String questionScore;
	/**
	 * 试题类型 1选择题 2代码题
	 */
	@OneToOne
	@JoinColumn(name="type")
	private QuestionTypeModel questionType;
	
	/**
	 * 出题人
	 */
	@OneToOne
	@JoinColumn(name="createdid")
	@JsonIgnoreProperties("pic")
	private AccountModel created;
	
	/**
	 * 创建时间
	 */
	@CreationTimestamp
	private Timestamp creationDate ;
	
	/**
	 * 修改时间
	 */
	@UpdateTimestamp
	private Timestamp updateDate ;
	
	/**
	 * 试卷
	 */
	@ManyToMany
	@JoinTable(
		      name="REL_QUESTION_PAPER",
		      joinColumns=@JoinColumn(name="QUESTION_ID", referencedColumnName="ID"),
		      inverseJoinColumns=@JoinColumn(name="PAPER_ID", referencedColumnName="ID"))
	@JsonIgnoreProperties("questions")
	private Set<TestPaperModel> papers;
	
}
